# -*- mode: snippet -*-
# name: gauss
# key: gauss
# --
const int N = 110;
double a[N][N];
int n;

int gauss() {
  int r = 0, c = 0, t;
  for (; c < n; ++c) {
    t = r;
    for (int i = r; i < n; ++i) {
      if (fabs(a[i][c]) > fabs(a[t][c])) t = i;
    }

    if (fabs(a[t][c]) < eps) continue;
    for (int j = c; j <= n; ++j) swap(a[t][j], a[r][j]);
    for (int j = n; j >= c; --j) a[r][j] /= a[r][c];

    for (int i = r + 1; i < n; ++i) {
      if (fabs(a[i][c]) > eps) {
        for (int j = n; j >= c; --j) {
          a[i][j] -= a[i][c] * a[r][j];
        }
      }
    }

    ++r;
  }

  if (r < n) {
    for (int i = r; i < n; ++i) {
      if (fabs(a[i][n]) > eps) return 2; // no solution
    }
    return 1;			// many solutions
  }

  for (int i = n - 1; i >= 0; --i) {
    for (int j = i + 1; j < n; ++j) {
      a[i][n] -= a[i][j] * a[j][n];
    }
  }

  return 0;			// unique solution
}
